/*=====================================================
Critical Links
Auto Configuration Server

Authors:
	Rui Eduardo Gouveia Gil - r-gil@critical-links.com

Date: 2010
Version 0.1
=======================================================*/
#include <rgcpp/utils/LogHandler.h>
#include "ACSConfig.h"

namespace acs
{

unsigned int ACSConfig::port=8099;
std::string ACSConfig::contentPath="/var/eacs/";
std::string ACSConfig::privateKeyFile="/var/eacs/server.key";
std::string ACSConfig::certificateFile="/var/eacs/server.crt";

void ACSConfig::setSystemDirectory(std::string contentPath)
{
	ACSConfig::contentPath=contentPath;

	if(ACSConfig::contentPath.empty() || ACSConfig::contentPath[ACSConfig::contentPath.size()-1] != '/')
		ACSConfig::contentPath += "/";
}

void ACSConfig::checkSystemDirectory()
{
	if(!boost::filesystem::exists(ACSConfig::contentPath))
	{
		LOG_FATAL_STR(std::string("Invalid base directory: ")+ACSConfig::contentPath);
		exit(-1);
	}
	else
	{
		if(!boost::filesystem::exists(ACSConfig::getDataDirectory()))
			boost::filesystem::create_directory(ACSConfig::getDataDirectory());

		if(!boost::filesystem::exists(ACSConfig::getDataBaseDirectory()))
			boost::filesystem::create_directory(ACSConfig::getDataBaseDirectory());
	}
}

void ACSConfig::setPort(unsigned int port)
{
	ACSConfig::port=port;
}

unsigned int ACSConfig::getPort()
{
	return ACSConfig::port;
}

void ACSConfig::setPrivateKeyFile(std::string path)
{
	ACSConfig::privateKeyFile = path;
}

std::string ACSConfig::getPrivateKeyFile()
{
	return ACSConfig::privateKeyFile;
}

void ACSConfig::setCertificateFile(std::string path)
{
	ACSConfig::certificateFile = path;
}

std::string ACSConfig::getCertificateFile()
{
	return ACSConfig::certificateFile;
}

std::string ACSConfig::getWebDirectory()
{
	return (ACSConfig::contentPath+"www/");
}

std::string ACSConfig::getDataDirectory()
{
	return (ACSConfig::contentPath+"data/");
}

std::string ACSConfig::getDataBaseDirectory()
{
	return (ACSConfig::contentPath+"db/");
}

}
